﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dreamz
{
    class EventCode
    {
        static bool CraniumFilled;

        static public void Apply()
        {
            
            Rum0.Apply();
            Rum3.Apply();
            Rum4.Apply();
            Rum6.Apply();
            Rum11.Apply();
            Rum9.Apply();
            Rum10.Apply();
            Rum17.Apply();
        }

        class Rum17
        {
            static public void Apply()
            {
                GameEngine.S.World[2, 6].Items["lever"].OnUse += new EventHandler(UseLever);
            }

            static public void UseLever()
            {
               //JONATHANS KOMMENTAR: Det vore en bra idé om du kunde göra så att den plockar bort stenen från världen vid start av spelet,
               //Sen ändrar på vault's description och lägger in stenen igen när man utfört pusslet. Ska försöka göra något liknande med cranium. (ball shaped piece of wood)
               //Se use cranium, tog sin lilla tid, men det gick
               // ___  ___  ___ 
               //| . || . >/ __>
               //| | || . \\__ \
               //`___'|___/<___/

                /*while (true)
{
   var ch = Console.ReadKey(false).Key;
   switch(ch)
   {
       case Console.Escape:
          ShutdownRobot();
          return;
       case Console.UpArrow:
          MoveRobotUp();
          break;
       case Console.DownArrow:
          MoveRobotDown();
          break;*/
            }
        }

        class Rum11
        {
            static public void Apply()
            {
                GameEngine.S.World[4, 3].Items["cube"].OnTake += new EventHandler(TakeCube);
                GameEngine.S.World[4, 3].Items["map"].OnTake += new EventHandler(TakeMap);
            }
            static public void TakeMap()
            {
                GameEngine.S.World[4, 3].Items["trapdoor"].Description = "You slowly put your eye to the slit at the edge of the trapdoor, and then rush back, afraid of monsters.";
                GameEngine.S.Player.Inventory["map"].OnUse += new EventHandler(Map);
                Console.Write("You may now use the map, by ");
                GameEngine.S.WriteColored("Using", ConsoleColor.Blue);
                Console.Write(" the map.\n\n");    
            }
            static public void TakeCube()
            {
                GameEngine.S.World[4, 3].Items["table"].Description = "This table grows more and more unstable, some greedy bastard stole its footpad.";
                GameEngine.S.Player.Inventory["Cube"].OnUse += new EventHandler(UseCube);
            }
            static public void UseCube()
            {
               //This method is for inserting the cube into a doorway, works together with UseTriangle, UseBall to open the door.
               Rum9.InsertShape("cube");
            }
            static public void Map()
            {
                Console.Clear();
                GameEngine.S.ScreenDrawer.Draw(@"
/////////////.////////////////////////////////////////////////////////////////////////////////////////////////////
///////////b   A//////////////////////////////////////////////////////////////////////////////////////////////////
///////////$b  Vb.////////////////////////////////////////////////////////////////////////////////////////////////
////////////$$b  V$$b.////////////////////////////////////////////////////////////////////////////////////////////
///////////'$$b. V$$$$oooooooo.///////////////////////////////////////////////////////////////////////////////////
//////////////'$$P* V$$$$$''**$$$b.///.o$$P////////////////////////////////////############///////////////////////
//////////////' .oooZ$$$$b..o$$$$$$$$$$$$C/////////////////////////////////////##        ##///////////////////////
//////////////.$$$$$$$$$$$$$$$$$$$$$$$$$$$b.///////////////////////////////////##        ##///////////////////////
//////////////$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$///////////////////////////////////##        ##///////////////////////
////////.o$$$o$$$$$$$$P''*$$$$$$$$$P'''*$$$P///////////////////////////////////##        ##///////////////////////
///////.$$$**$$$$P'q$C    '$$$b        .$$P//////////////////////////###############  #####////////############///
///////$$P   '$$$b  '$ . .$$$$$b.*'//////////////////////////////////##        ##        ############        ##///
///////$$      $$$.     '***$$$$$$$b. A./////////////////////////////##                  ##                  ##///
//////V$b   . Z$$b.  .       '*$$$$$b$$://///////////////////////////##                  ##                  ##///
////////V$$.  '*$$$b.  b.         '$$$$$/////////////////////////////##        ##        ############        ##///
/////////'$$b     '*$.  *b.         '$$$b////////////////////////////###############  #####////////############///
///////////'$$b.     'L  '$$o.        '*'/////.ooo..///////////////////////////##        ##///////////////////////
/////////////'*$$o.        '*$$o.         /.o$$$$$$$$b.////////////////////////##        ##///////////////////////
/////////////////'*$$b.       '$$b.       .$$$$$*'///''*.//////////////////////##        ##///////////////////////
////////////////////'*$$o.      '$$$o.    $$$$$'///////////////////////////////##        ##///////////////////////
///////////////////////'$$o       '$$$b.  '$$$$///...oo.. /#########################..#########################///
/////////////////////////'$b.      '$$$$b. '$$$$$$$P*'''''/##        ##        ##        ##        ##        ##///
////////////////////////./'$$       '$$$$b  '$$$$P'////////##                                           Map  ##///
/////////////////////////L.'$.      .$$$$$.  $$$$//////////##                                            X   ##///
//////////.. /////////////$$$;      o$$$$$$  $$$$//////////##        ##        ##        ##        ##        ##///
///////. $.l  ////////////'$$'    .$$$$$$$P  $$$P//////////###############  ##################  ###############///
/////.I .$b b '. 'P //////      .P*''*$$$$;  $$$/////////////////////##        ##////////##        ############///
///.$P  $$o '. '.  ./////   ' .'      $$$$   $$;/////////////////////##        ##////////##        ###      ###///
//.$$;  $$$. 'A '$. './      '       o$$$P  .$P//////////////////////##        ##////////##        ##        ##///
/.$$$b  $$$$. *$. '$$$$o.          .$$$$P   $'///////////////////////##        ##////////##        ##        ##///
.$$$$$  $$$$$. '$$o.'**$$$$o.'  .o$$$$P'    P////////////////////////#########################  ########  #####///
$$P'$$b $$$$$$o  '*$$$$boooooc$$$$$$$P'   . ///////////////////////////////////##        ##        ##        ##///
$$//$$$.'$$$'*$$.   '$$$$$$$$$$$$$$$$C  .o'////////////////////////////////////##                            ##///
I'//$P'$.'$$b. '*$.    '**$$$$$*'*$$$$$$$'/////////////////////////////////////##                            ##///
'///$//'$.'$$$.   '''    //////////'*$$*///////////////////////////////////////##        ##        ##        ##///
////$.///'.'$$$$o       ///////////////////////////////////////////////////////###############  ###############///
////'I///////'$$$$b. .   ////////////////////////////////////////////////////////////////##        ##/////////////
////////////////'$$$b.'$o.///////////////////////////////////////////////////////////////##        ##/////////////
//////////////////'*$$.'$$$o.////////////////////////////////////////////////////////////##        ##/////////////
////////////////////'$$o $$$$b.//////////////////////////////////////////////////////////##        ##/////////////
/////////////////////'$$o'$$$$$b.////////////////////////////////////////////////////////############/////////////
//////////////////////'$$.'$$$**$o////////////////////////////////////////////////////////////////////////////////
///////////////////////'$$.$$$./'$$///////////////////////////////////////////////////////////////////////////////
////////////////////////$$; $$$o./'$./////////////////////////////////////////////////////////////////////////////
////////////////////////'$: $$/'*o//'.////////////////////////////////////////////////////////////////////////////
/////////////////////L///$$ $P////l//'.///////////////////////////////////////////////////////////////////////////
/////////////////////$./.$$ $;////////////////////////////////////////////////////////////////////////////////////
/////////////////////;$.$$P $/////////////////////////////////////////////////////////////////////////////////////
/////////////////////'$$$$ P'/////////////////////////////////////////////////////////////////////////////////////
////////////////////$$$;://///////////////////////////////////////////////////////////////////////////////////////
//////////////////////$$P/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////o$P//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////P///////////////////////////////////////////////////////////////////////////////////////////
/////////////////////I'///////////////////////////////////////////////////////////////////////////////////////////"
                    ,-14, 0);
                GameEngine.S.ScreenDrawer.Draw("You are at the blinking cursor. Press any button to return to game.", 30, 49);
                GameEngine.S.ScreenDrawer.Present();
                Console.SetCursorPosition(51 + GameEngine.S.Player.X * 10, Console.WindowHeight - (13 + GameEngine.S.Player.Y * 5));
                Console.ReadKey();
                GameEngine.S.Player.DescribeCurrentRoom();
            }
        }

        class Rum10
        {
            static public bool leverMovable = false; 
            static public void Apply()
            {
                GameEngine.S.World[3, 3].Items["lever"].OnUse += new EventHandler(UseLever);
            }
            static public void UseLever()
            {
                if (leverMovable == true)
                {
                    Console.WriteLine("You move the tounge with a mighty heave. The lion seem to melt away, fading into the wall.\nAs the lion merges fully with the wall, a big hole emerges. Where does it lead?");
                    GameEngine.S.World[3, 3].Description = "You see a lion-shaped hole in the wall.\n";
                    GameEngine.S.World[3, 3].North = true;
                }
            }
        }
        class Rum9
        {
           static public void InsertShape(string shape)
           {
              if (GameEngine.S.Player.X == 2 && GameEngine.S.Player.Y == 3)
              {
                 string UseTarget;
                 Console.WriteLine("What do you want to use the {0} on?\n", shape);
                 UseTarget = Console.ReadLine().ToLower();
                 //Asks what you want to do with your shape (shaped wood etc)
                 if (UseTarget == "hole" || UseTarget == "holes" || UseTarget == "door")
                 {
                    //if you want to use it on the opening-mechanism
                    Console.WriteLine("You insert the {0} into the {1}-shaped hole.\n", shape, shape);
                    //Confirmation that you succeeded
                    switch (shape)
                    {
                       case "ball":
                          Door.S.ball = true;
                          break;
                       case "triangle":
                          Door.S.triangle = true;
                          break;
                       case "cube":
                          Door.S.cube = true;
                          break;
                    }
                    //Sets different bools of the class door to true depending on what shapes you've inserted.
                    GameEngine.S.World[2, 3].Items["hole"].Description = "These holes are shaped in different geometrical figures, there are holes for a triangle, a square and a ball.";
                //TODO:Checken att dörren har alla items i sig, ändring av descriptionen beroende på shapes som satts in, alt removal av item då man sätter in det (så att man inte kan sätta in ett item flera gånger)
                 }
              }
           }
        }
        class Rum6
        {
           static public void Apply()
           {
              GameEngine.S.World[4, 2].Items.Remove("ball");   
           }
           static public void TakeBall()
           {
              GameEngine.S.Player.Inventory["ball"].OnUse += new EventHandler(UseBall);
           }
           static public void UseBall()
           { 
              //This method is used to insert a ball into a doorway, works together with UseTriangle, UseCube to open the door.
              Rum9.InsertShape("ball");
           }
        }
        class Rum4
        {
            static public void Apply()
            {
                GameEngine.S.World[1, 2].Items["triangle"].OnTake += new EventHandler(TakeTriangle);
            }
            static public void TakeTriangle()
            {
                GameEngine.S.World[1, 2].Items["chest"].Description = "This chest is empty, and feeling pretty lonely.\n";
                GameEngine.S.Player.Inventory["triangle"].OnUse += new EventHandler(UseTriangle);
            }
            static public void UseTriangle()
            {
               //This method is used for inserting the triangle into a doorway, work together with useBall, UseCube to open the door.
               Rum9.InsertShape("triangle");
            }
        }

        class Rum3
        {
            static public void Apply()
            {
                GameEngine.S.World[4, 1].Items["cranium"].OnTake += new EventHandler(TakeCranium);
                GameEngine.S.World[4, 1].Items["holy hand grenade"].OnTake += new EventHandler(TakeGrenade);
            }

            static public void TakeCranium()
            {
                GameEngine.S.World[4, 1].Description = "This room contains a set of crown jewels, and an odd, noisy contraption.\n";
                GameEngine.S.Player.Inventory["cranium"].OnUse += new EventHandler(UseCranium);
            }
            static public void UseCranium()
            {
                string UseTarget;
                if(GameEngine.S.Player.X ==0&&GameEngine.S.Player.Y==3)
                {
                    Console.Write("What do you want to use the Cranium on?\n");
                    UseTarget = Console.ReadLine().ToLower();
                    if (UseTarget == "liquid" || UseTarget == "stream")
                    {
                        GameEngine.S.Player.Inventory["cranium"].Description = "This is the cranium of a giant bull. It's filled with an un-identified liquid.\n";
                        EventCode.CraniumFilled = true;
                        Console.Write("You use the cranium as a bowl to hold the unidentified liquid.\n");
                    }
                    else
                    {
                        Console.Write("Stop this Gibberish!\n");
                    }
                    
                }
                else if (GameEngine.S.Player.X == 4 && GameEngine.S.Player.Y == 2)
                {
                    Console.Write("What do you want to use the Cranium on?\n");
                    UseTarget = Console.ReadLine().ToLower();
                    if (UseTarget == "hole" && EventCode.CraniumFilled)
                    {
                        Console.Write("You fill the hole with the un-identified liquid. An object float up to the surface.\n");
                        String item = "Ball|wood|Ball-shaped piece of wood#It's made out of wood, and round, duh#canPickUp";
                        GameEngine.S.World[4, 2].Items.Add(item.Split('|')[0].ToLower(), Item.FromString(item));
                        GameEngine.S.World[4, 2].Items["ball"].OnTake += new EventHandler(Rum6.TakeBall);
                        GameEngine.S.World[4, 2].Items["hole"].Description = "This is a hole filled with water, it contains A Ball-shaped piece of wood.\n";
                        GameEngine.S.Player.Inventory["cranium"].Description = "This is the cranium of a giant bull. It's slightly wet.\n";
                    }
                }
                else
                {
                    Console.Write("Stop this Gibberish!\n");
                }


            }
            static public void TakeGrenade()
            {
                GameEngine.S.World[4, 1].Items["crown jewels"].Description = "This is a set of crown jewels, you see a crown, a sceptre, but something seems to be missing...\n";
            }
        }

        class Rum0
        {
            static public void Apply()
            {
                GameEngine.S.World[3, 0].Items["key"].OnUse += new EventHandler(UnlockDoor);
                GameEngine.S.World[3, 0].Items["candles"].OnTake += new EventHandler(TakeCandles);
            }
            static public void TakeCandles()
            {
                GameEngine.S.World[3, 0].Description = "You enter a cell with a rotten corpse on the ground.\n";
                //TODO Ändra candles till "stone" (eller vad det heter) och flytta texten till rum 17 i kassaskåp.
                GameEngine.S.Player.Inventory["candles"].OnUse += new EventHandler(TipOfTounge);
            }
            static void TipOfTounge()
            {
                //TODO Ändra candles till "stone" (eller vad det heter) och flytta texten till rum 17 i kassaskåp.
                if (GameEngine.S.Player.Inventory["candles"] != null)
                {
                    if (GameEngine.S.Player.CurrentRoom == GameEngine.S.World[3, 3])
                    {
                        GameEngine.S.World[3, 3].Description = "As you enter this room, you notice a giant lion-statue, it's mouth wide open.\nThe statue is made out of stone, the tounge vaguely resembling a lever.\n";
                        Rum10.leverMovable = true;
                        Console.WriteLine("As you replace the tip of the tounge, the lion suddenly gapes.\n");
                    }
                }
            }
            static public void UnlockDoor()
            {
                GameEngine.S.World[3, 0].North = !GameEngine.S.World[3, 0].North;
               //Code to open/close the door in the room where you start
                if (GameEngine.S.World[3, 0].North == true)
                {
                    Console.Write("You unlocked the door, you may now go to the ");
                    GameEngine.S.WriteColored("[north]\n", ConsoleColor.Green);
                }
                else
                {
                    Console.Write("You locked the door, you fool!\n");
                }
            }
        } 
    }
    public delegate void EventHandler();
}